import 'package:dartkit/dartkit.dart';
import 'package:test/test.dart';

void main() {
  setUpAll(() {
    argSecret.value = "secret";
  });
  final subject = "主体";
  test("正常颁发与核销", () {
    // 通过传入一个主体，然后核销，能恢复这个主体信息
    final token = TokenKit.issue(subject: subject);
    final redeemed = TokenKit.redeem(token);
    expect(redeemed == subject, isTrue);
  });

  test("Bearer测试", () {
    // 假如Bearer前缀后，依然能够顺利核销出主体
    final token = "Bearer ${TokenKit.issue(subject: subject)}";
    final redeemed = TokenKit.redeem(token);
    expect(redeemed == subject, isTrue);
  });

  test("超过有效期限", () async {
    // 将颁发的时间设置成零，然后核销
    // 预计就会报错
    final token = TokenKit.issue(subject: subject, validTime: Duration.zero);
    expect(() => TokenKit.redeem(token), isBug);
  });
}
